package com.bitinstitute.parkapp.home;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.bitinstitute.parkapp.R;
import com.bitinstitute.parkapp.helper.ImageLoader;
import com.bitinstitute.parkapp.helper.TabGroupActivity;

public class HomeSingleMenuItemActivity extends Activity {

	// XML node keys
	static final String KEY_NAME = "name";
	static final String KEY_DATE = "date";
	static final String KEY_HEADING1 = "heading1";
	static final String KEY_DESC1 = "description1";
	static final String KEY_HIGHLIGHT = "highlight";
	static final String KEY_THUMB_URL = "thumb_url";
	static final String KEY_WEB_URL = "web_url";

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		setContentView(R.layout.home_single_list_item);

		// getting intent data
		Intent in = getIntent();

		// Get XML values from previous intent
		String name = in.getStringExtra(KEY_NAME);
		String date = in.getStringExtra(KEY_DATE);

		String heading1 = in.getStringExtra(KEY_HEADING1);
		String desc1 = in.getStringExtra(KEY_DESC1);

		String highlight = in.getStringExtra(KEY_HIGHLIGHT);

		final String web_url = in.getStringExtra(KEY_WEB_URL);

		// Displaying all values on the screen
		TextView lblName = (TextView) findViewById(R.id.name_label);
		TextView lblDate = (TextView) findViewById(R.id.date_label);

		TextView lblHeading1 = (TextView) findViewById(R.id.heading1_label);
		TextView lblDesc1 = (TextView) findViewById(R.id.desc1_label);
		TextView lblHighlight = (TextView) findViewById(R.id.highlight_label);

		lblName.setText(name);
		lblDate.setText(date);

		lblHeading1.setText(heading1);
		lblDesc1.setText(desc1);
		lblHighlight.setText(highlight);

		// Imageview to show
		ImageView image = (ImageView) findViewById(R.id.header_picture);

		// Image url
		String image_url = in.getStringExtra(KEY_THUMB_URL);

		// ImageLoader class instance
		ImageLoader imgLoader = new ImageLoader(getApplicationContext());

		// url - image url to load
		// image - ImageView
		imgLoader.DisplayImage(image_url, image);

		// web_url onClick
		findViewById(R.id.web_url_label).setOnClickListener(
				new OnClickListener() {

					public void onClick(View v) {

						// Starting new intent
						Intent intent = new Intent(getApplicationContext(),
								DisplayWeb.class);
						intent.putExtra(KEY_WEB_URL, web_url);

						TabGroupActivity parentActivity = (TabGroupActivity) getParent();
						parentActivity.startChildActivity("DisplayWeb", intent);

					}
				});

		// Back Button
		findViewById(R.id.btnBack).setOnClickListener(new OnClickListener() {

			public void onClick(View v) {

				dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN,
						KeyEvent.KEYCODE_BACK));

				dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP,
						KeyEvent.KEYCODE_BACK));

			}
		});
	}
}
